#include<bits/stdc++.h>

using namespace std;
using ll = long long;
#define endl '\n'
int b[8];
int book[8];

bool judge() {
    for (int i = 0; i < 8; i++)
        for (int j = i + 1; j < 8; j++) {
            //Q[i](i,b[i])  Q[j](j,b[j])
            if (j - i == abs(b[i] - b[j])) {
                return false;
            }
        }
    return true;
}

void dfs(int k) {
    if (k >= 8) {

        if (judge()) {
            copy(b, b + 8, ostream_iterator<int>(cout, ""));
            cout << endl;
        }
        return;
    }
    for (int i = 0; i < 8; i++) {
        if (book[i])continue;
        book[i] = 1;
        b[k] = i;
        dfs(k + 1);
        book[i] = 0;
    }


}

int main() {
    dfs(0);
    return 0;
}
